package org.rslai.autotest.core.page.impl;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.rslai.autotest.core.page.AbstractHelper;
import org.rslai.autotest.core.page.Checkbox;
import org.rslai.autotest.core.page.Click;
import org.rslai.autotest.core.page.Wait;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Checkbox处理方法
 * @author rslai
 */
public class CheckboxImpl extends AbstractHelper implements Checkbox {

	@Autowired
	private Click click;

	@Autowired
	private Wait wait;
	
	@Override
	public boolean checkboxIsChecked(By by) {
		return this.wait.waitForElement(by).isSelected();
	}

	@Override
	public boolean checkboxIsChecked(WebElement webElement) {
		return webElement.isSelected();
	}

	@Override
	public void checkboxChecked(By by) {
		if (!this.checkboxIsChecked(by)) {
			this.click.click(by);
		}
	}

	@Override
	public void checkboxChecked(WebElement webElement) {
		if (!this.checkboxIsChecked(webElement)) {
			webElement.click();
		}
	}

	@Override
	public void checkboxUnChecked(By by) {
		if (this.checkboxIsChecked(by)) {
			this.click.click(by);
		}
	}

	@Override
	public void checkboxUnChecked(WebElement webElement) {
		if (this.checkboxIsChecked(webElement)) {
			webElement.click();
		}
	}

}
